package org.eclipse.bpel.model.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.eclipse.bpel.model.Variable;
import org.eclipse.emf.common.util.EList;
import org.eclipse.wst.wsdl.ExtensibleElement;

public class FindVariablesAction implements SwitchAction {
	
	private static transient Logger log = Logger.getLogger(FindVariablesAction.class);
	
//	private EList<Variable> varList;
	
	private List<Variable> varList = new ArrayList<Variable>();
	
//	public void setVarList(EList<Variable> varList) {
//		this.varList = varList;
//	}

	public List<Variable> getVarList() {
		return varList;
	}

	@Override
	public void doPostAction(ExtensibleElement element) {
		if (element instanceof Variable) {
			Variable var = (Variable) element;
//			log.trace("Variable: " + var.getName() + " found");
			
			
//			if (null != varList) {
//				// This executes EMF code. In EMF var is defined to 
//				// be a containment relation which means that if 
//				// a variable is added to another list, then it is removed
//				// from the prior list, as an element is only allowed to 
//				// be contained (EMF contained relation) inside a single list!
//				//
//				// This is bad!
//				varList.add(var);
//			}
			
			
			varList.add(var);
		}
	}

	@Override
	public void doPreAction(ExtensibleElement element) {
		
	}

}
